package com.kensure.shike.user.service;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import co.kensure.frame.JSBaseService;

import com.kensure.shike.user.dao.SKRoleDao;
import com.kensure.shike.user.model.SKRole;

/**
 * 角色表服务实现类
 * 
 * @author fankd created on 2018-9-8
 * @since
 */
@Service
public class SKRoleService extends JSBaseService {

	@Resource
	private SKRoleDao dao;

	public SKRole selectOne(Long id) {
		return dao.selectOne(id);
	}

	public List<SKRole> selectByIds(Collection<Long> ids) {
		return dao.selectByIds(ids);
	}

	public List<SKRole> selectByWhere(Map<String, Object> parameters) {
		return dao.selectByWhere(parameters);
	}

	public long selectCountByWhere(Map<String, Object> parameters) {
		return dao.selectCountByWhere(parameters);
	}

	public boolean insert(SKRole obj) {
		return dao.insert(obj);
	}

	public boolean update(SKRole obj) {
		return dao.update(obj);
	}

	public boolean updateByMap(Map<String, Object> params) {
		return dao.updateByMap(params);
	}

	private static Map<String, SKRole> allrole = new HashMap<>();

	/**
	 * 初始化
	 */
	public void initRoleMap() {
		List<SKRole> list = selectByWhere(null);
		for (SKRole role : list) {
			allrole.put(role.getLevelCode(), role);
		}
	}

	/**
	 * 根据编码寻找角色
	 * 
	 * @param code
	 * @return
	 */
	public static SKRole selectRoleByCode(String code) {
		SKRole role = allrole.get(code);
		return role;
	}

}
